package com.example.vspm.controller;

import com.example.vspm.entity.Person;
import com.example.vspm.entity.Result;
import com.example.vspm.service.impl.LoginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private LoginServiceImpl lsi;

    @RequestMapping("/index")
    public String indexAction() {
        System.out.println("执行了index方法");
        return "login";
    }

    @PostMapping("/login")
    public String loginAction(Person person, HttpSession session,Model model) {
        Result res = lsi.login(person, session);
        Object obj = session.getAttribute("person");
        Person per = (Person)obj;
        String cap = per.getCapacity();
      model.addAttribute("res",res);
      String mv = "";
        switch (cap) {
            case "100":
               mv = "poster/index";
                break;
            case "010":
                mv = "sender/index";
                break;
            case "001":
                mv = "receiever/index";
                break;
            case "111":
                mv = "grant/index";
            default:
                mv = "login";
                break;
        }
        return mv;
    }
}


